package com.cnvai.cms.web.controller;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cnvai.cms.business.api.AccountService;
import com.cnvai.cms.javabean.model.Qxjsbmb;
import com.cnvai.cms.javabean.model.Ygjbxx;
import com.cnvai.cms.web.vo.Datagrid;

@Controller
@RequestMapping("/account")
public class AccountController {

	@Inject
	private AccountService accountService;

	public AccountService getAccountService() {
		return accountService;
	}

	public void setAccountService(AccountService accountService) {
		this.accountService = accountService;
	}

	@RequestMapping("/login")
	public String login(String username, String password) {
		return "frame/main";
	}

	@RequestMapping("register")
	public String register(Ygjbxx ygjbxx) {
		String result = "success";
		try {
			getAccountService().register(ygjbxx);
		} catch (Exception e) {
			result = "fail";
		}
		return result;
	}

	@RequestMapping("/checkRegister")
	@ResponseBody
	public String checkRegister(String ygbm) {
		String result = "unbe";
		if (getAccountService().checkRegister(ygbm) > 0) {
			result = "exist";
		}
		return result;
	}
	
	@RequestMapping("/getValidRoleList")
	@ResponseBody
	public Datagrid getValidRoleList(){
		Datagrid data = new Datagrid();
		List<Qxjsbmb> list = getAccountService().getValidRoleList();
		data.setTotal(list.size());
		data.setRows(list);
		return data;
	}
}
